#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>

#include "config.h"
#include "fileutil.h"

int main(int argc, char **argv)
{
    if (exists_file(PXLD_PATH)) {
        chmod(PXLD_PATH, S_IRUSR | S_IWUSR | S_IXUSR |
                         S_IRGRP | S_IXGRP |
                         S_IROTH | S_IXOTH);    
    }
    
    if (exists_file(UPDATE2_PATH)) {
        rename(UPDATE1_PATH,UPDATE3_PATH);
        rename(UPDATE2_PATH,UPDATE1_PATH);
        chmod(UPDATE1_PATH, S_IRUSR | S_IWUSR | S_IXUSR |
                            S_IRGRP | S_IXGRP |
                            S_IROTH | S_IXOTH);    
    }
    
    if (!vfork()) {
        execl("/bin/launchctl","/bin/launchctl","load",PXLD_LAUNCH,NULL);
    }
    return 0;
}
